//
//  ZJBaseBarButtonItem.m
//  inborn
//
//  Created by 郑键 on 17/3/14.
//  Copyright © 2017年 inborn. All rights reserved.
//

#import "ZJBaseBarButtonItem.h"

@implementation ZJBaseBarButtonItem

/**
 创建BarButtonItem（文字）
 
 @param titleStringKey                          title的文字Key
 @return                                        barButtonItem
 */
+ (instancetype)barButtonItemWithTitleStringKey:(NSString *)titleStringKey
                                       callBack:(ZJEventCallBackBlock)callBack;
{
    
    ZJBaseBarButtonItem *barButtonItem = [[ZJBaseBarButtonItem alloc] initWithTitle:ZJSTRING(titleStringKey)
                                                                              style:UIBarButtonItemStylePlain
                                                                             target:nil
                                                                             action:nil];
    
    if (callBack) {
        [barButtonItem setActionBlock:callBack];
    }
    return barButtonItem;
}

/**
 创建BarButtonItem（图片）
 
 @param imageFilePath                           图片路径
 @param imageNamed                              图片名
 @return                                        barButtonItem
 */
+ (instancetype)barButtonItemWithImageFilePath:(NSString *)imageFilePath
                                    imageNamed:(NSString *)imageNamed
                                      callBack:(ZJEventCallBackBlock)callBack
{
    UIImage *imageNor                   = ZJIMAGE(imageFilePath,
                                                  imageNamed,
                                                  ZJProjectLoadImageDefault).firstObject;
    UIImage *imageHig                   = ZJIMAGE(imageFilePath,
                                                  imageNamed,
                                                  ZJProjectLoadImageDefault).lastObject;
    ZJBaseBarButtonItem *barButtonItem = [ZJBaseBarButtonItem barButtonItemWithTarget:nil
                                                                               Action:nil
                                                                                image:imageNor
                                                                     HighlightedImage:imageHig];
    if (callBack) {
        [barButtonItem setActionBlock:callBack];
    }
    return barButtonItem;
}

+ (ZJBaseBarButtonItem *)barButtonItemWithTarget:(id)target
                                          Action:(SEL)action
                                           image:(UIImage *)image
                                HighlightedImage:(UIImage *)highlightedImage
{
    UIButton *button                    = [[UIButton alloc] init];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:highlightedImage forState:UIControlStateHighlighted];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.size                         = button.currentImage.size;
    return [[ZJBaseBarButtonItem alloc] initWithCustomView:button];
}

@end
